package com.zbiti.anvil.basic.module.business.service.service.impl;


import com.zbiti.anvil.basic.module.business.api.domain.BookCategory2Domain;
import com.zbiti.anvil.basic.module.business.api.service.IBookCategory2Service;
import com.zbiti.anvil.basic.module.business.service.mapper.Book2Mapper;
import com.zbiti.anvil.basic.module.business.service.mapper.BookCategory2Mapper;
import com.zbiti.module.common.service.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * book_category2 数据库基础操作接口实现
 *
 * @author generator
 * @date 2025-04-08 12:17:44
 */
public class BookCategory2ServiceImpl extends BaseServiceImpl<BookCategory2Mapper, BookCategory2Domain> implements IBookCategory2Service {

    /**
     * 构造函数
     *
     * @param baseMapper Mapper对象
     */
    public BookCategory2ServiceImpl(BookCategory2Mapper baseMapper) {
        super(baseMapper);
    }

    @Autowired
    private BookCategory2Mapper bookCategoryMapper;
    @Autowired
    private Book2Mapper bookMapper;

    @Override
    public int deleteCategoryAndBooks(Integer id) {
        String categoryName = bookCategoryMapper.getCategoryNameById(id);
        if (categoryName == null) {
            throw new RuntimeException("未找到对应的分类");
        }

        // 删除 book2 中对应分类的记录
        int booksDeleted = bookMapper.deleteByCategoryName(categoryName);

        // 删除 book_category2 中的记录
        int categoryDeleted = bookCategoryMapper.deleteById(id);

        // 返回删除的总条数
        return booksDeleted + categoryDeleted;
    }
    }

    // 在此处定义业务需要的接口，基础的增删改查接口实现请参考“BaseServiceImpl”类


